package com.xdf.whiteaccount.controller;

import com.xdf.whiteaccount.entity.BillDyeGrey;
import com.xdf.whiteaccount.entity.BillDyeGrey4Jrkbillsum;
import com.xdf.whiteaccount.entity.ResponseResult;
import com.xdf.whiteaccount.enums.MenuConstant;
import com.xdf.whiteaccount.enums.OperateConstant;
import com.xdf.whiteaccount.enums.ResponseEnum;
import com.xdf.whiteaccount.enums.SeparatorConstant;
import com.xdf.whiteaccount.service.BillDyeGreyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "染厂白坯管理（发货入库）")
@CrossOrigin
@RestController
@RequestMapping("/dyeGrey")
public class BillDyeGreyController {
    @Autowired
    private BillDyeGreyService service;

    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "通过单据数据新增，模型参照类型 BillDyeGrey")
    //@RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertSelective", method = RequestMethod.POST)
    public ResponseResult<Void> insertSelective(@RequestBody BillDyeGrey record) throws Exception {
        service.insert(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "扫描发货", httpMethod = "POST", notes = "通过扫描货架号传递来白坯打卷汇总表主键数组（整型数组）进行发货" +
            "请求URL：http://localhost:8083/huachongjin/dyeGrey/insertScan" +
            "参数：[1,2,3,4]" +
            "参数中的数字是 jrkbillsum.id")
    //@RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertScan", method = RequestMethod.POST)
    public ResponseResult<Void> insertScan(@RequestBody List<Integer> jrkbillsumIdList) throws Exception {
        service.insert(jrkbillsumIdList);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "根据主键删除方法", httpMethod = "DELETE", notes = "自动生成的删除方法")
    //@RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.DELETE)
    @RequestMapping(value = "/deleteByPk", method = RequestMethod.POST)
    public ResponseResult<Void> deleteByPrimaryKey(@RequestParam("id") Integer id) throws Exception {
        service.delete(id);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "选择修改", httpMethod = "PUT", notes = "自动生成的修改方法")
    //@RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.MODIFY)
    @RequestMapping(value = "/updateSelective", method = RequestMethod.POST)
    public ResponseResult<Void> updateSelective(@RequestBody BillDyeGrey record) throws Exception {
        service.update(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "根据主键查询", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/queryByPk/{id}", method = RequestMethod.GET)
    public BillDyeGrey selectByPrimaryKey(@PathVariable("id") Integer id) throws Exception {
        if (id == null) return null;
        return service.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "通过单据数据新增，模型参照类型 BillDyeGrey")
    //@RequiresPermissions(MenuConstant.MENU203 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insert4Jrkbillsum", method = RequestMethod.POST)
    public ResponseResult<Void> insert4Jrkbillsum(@RequestBody BillDyeGrey4Jrkbillsum record) throws Exception {
        service.insert(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }
}
